package com.hmall.api.pay;

import com.hmall.api.pay.dto.PayOrderDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.Du
 * @Date 2025/6/23 2025/6/23
 */

@Component
@Slf4j
public class PayClientFallbackFactory implements FallbackFactory<PayClient> {

    /**
     * 降级处理逻辑
     *
     * @param cause
     * @return
     */
    @Override
    public PayClient create(Throwable cause) {
        return new PayClient() {
            @Override
            public PayOrderDTO queryPayOrderByBizOrderNo(Long id) {
                log.error("调用PayClient#queryPayOrderByBizOrderNo方法出现异常,参数:{},异常:", id, cause);
                //返回一个默认的空对象(表示在发生降级处理时给调用者一个固定的返回值)
                return new PayOrderDTO();
            }
        };
    }
}
